import {
  itemModel,userModel
} from './apis/index.js'
module.exports = {
  data: { someData: 'myMixin' },
  submitFormId(e) {
    itemModel.formIdAdd({form_id:e.detail.formId})
  },
  computedPage(pageFiled,total){
    let page = this.data[pageFiled]
    let totalPage = Math.ceil(total/page.pageSize)
    page.totalPage = totalPage
    page.page++
    this.data[pageFiled] = page
  },
  loadMoreData(pageFiled,method){
    let page = this.data[pageFiled]
    if(page.page>page.totalPage){
      return false;
    }
    method &&　method()
  },
  onShow(){
    let app = getApp()
    let {intervalCount} = app.globalData
    if(!intervalCount){
      app.globalData.intervalCount = setInterval(()=>{
        this.getUnreadCount()
      },30000)
    }
  },
  getUnreadCount(){
    itemModel.unreadCount().then(res=>{
      let {num} = res
      if(num>0){
        qq.setTabBarBadge({
          index:1,
          text:num.toString()
        })
      }else{
        qq.removeTabBarBadge({
          index:1
        })
      }
      
    })
  }
}
